package cn.rui.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.rui.common.ResponseBean;
import cn.rui.pojo.goods.Category;
import cn.rui.pojo.vo.PageVo;
import cn.rui.service.goods.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @author 徽州大都督
 * @date 2021/6/21
 */
@RestController
@RequestMapping("category")
@Api(tags = "商品分类模块")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation(value = "查询所有分类")
    @SaCheckLogin
    @GetMapping("findAll")
    public ResponseBean findAll() {
        return categoryService.findAll ();
    }


    @ApiOperation(value = "分页查询分类")
    @SaCheckLogin
    @PostMapping("findPage")
    public ResponseBean findPage(@RequestBody PageVo pageVo, HttpSession session) {
        return categoryService.findPage (pageVo);
    }

    @ApiOperation(value = "根据id删除分类")
    @SaCheckLogin
    @DeleteMapping("deleteById/{id}")
    public ResponseBean deleteById(@PathVariable("id")Long id) {
        return categoryService.deleteById (id);
    }

    @ApiOperation(value = "修改分类信息")
    @SaCheckLogin
    @PutMapping("updateCategory")
    public ResponseBean updateCategory(@RequestBody Category category) {
        return categoryService.updateCategory (category);
    }

    @ApiOperation(value = "添加分类")
    @SaCheckLogin
    @PostMapping("save")
    public ResponseBean save(@RequestBody Category category) {
        return categoryService.save (category);
    }
}
